<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Apache Shiro 权限框架完全指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            overflow-x: auto;
        }
        
        .feature-icon {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        .scroll-indicator {
            position: fixed;
            top: 0;
            left: 0;
            height: 4px;
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            transition: width 0.3s ease;
            z-index: 1000;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
    </style>
</head>
<body>
    <div class="scroll-indicator" id="scrollIndicator"></div>
    
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4">
        <div class="max-w-6xl mx-auto animate-fadeInUp">
            <div class="text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6">Apache Shiro</h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">Java 安全框架完全指南</p>
                <div class="flex justify-center space-x-6 text-lg">
                    <div class="flex items-center">
                        <i class="fas fa-shield-alt mr-2"></i>
                        <span>认证授权</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-lock mr-2"></i>
                        <span>会话管理</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-key mr-2"></i>
                        <span>加密缓存</span>
                    </div>
                </div>
            </div>
        </div>
    </section>
    
    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-4 py-12">
        
        <!-- Introduction Card -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">什么是 Apache Shiro？</h2>
            <p class="text-lg leading-relaxed text-gray-700 mb-6">
                Apache Shiro 是 Java 的一个安全（权限）框架。Shiro 可以非常容易的开发出足够好的应用，其不仅可以用在 JavaSE 环境，也可以用在 JavaEE 环境。相比 Spring Security，Shiro 更加简单易用，在实际工作中往往不需要过于复杂的功能，使用小而简单的 Shiro 就足够了。
            </p>
            <div class="bg-purple-50 border-l-4 border-purple-500 p-4 rounded">
                <p class="text-purple-800">
                    <i class="fas fa-lightbulb mr-2"></i>
                    <strong>核心功能：</strong>认证、授权、加密、会话管理、与 Web 集成、缓存等
                </p>
            </div>
        </div>
        
        <!-- Core Features Grid -->
        <div class="grid md:grid-cols-2 gap-6 mb-12">
            <div class="content-card rounded-xl shadow-lg p-6">
                <div class="flex items-center mb-4">
                    <i class="fas fa-user-check text-4xl feature-icon mr-4"></i>
                    <h3 class="text-2xl font-bold">Authentication 身份认证</h3>
                </div>
                <p class="text-gray-700">验证用户身份，确认用户是否拥有相应的身份。简单来说就是登录验证。</p>
            </div>
            
            <div class="content-card rounded-xl shadow-lg p-6">
                <div class="flex items-center mb-4">
                    <i class="fas fa-user-shield text-4xl feature-icon mr-4"></i>
                    <h3 class="text-2xl font-bold">Authorization 授权</h3>
                </div>
                <p class="text-gray-700">权限验证，验证已认证用户是否拥有某个权限，判断用户是否能执行特定操作。</p>
            </div>
            
            <div class="content-card rounded-xl shadow-lg p-6">
                <div class="flex items-center mb-4">
                    <i class="fas fa-clock text-4xl feature-icon mr-4"></i>
                    <h3 class="text-2xl font-bold">Session Manager 会话管理</h3>
                </div>
                <p class="text-gray-700">管理用户会话，在任何环境下使用 Session API，即使没有 Web 或 EJB 容器。</p>
            </div>
            
            <div class="content-card rounded-xl shadow-lg p-6">
                <div class="flex items-center mb-4">
                    <i class="fas fa-lock text-4xl feature-icon mr-4"></i>
                    <h3 class="text-2xl font-bold">Cryptography 加密</h3>
                </div>
                <p class="text-gray-700">使用加密算法保护数据安全，如密码加密存储，而非明文存储。</p>
            </div>
        </div>
        
        <!-- Architecture Visualization -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">Shiro 架构核心组件</h2>
            <div class="bg-gray-50 rounded-lg p-6">
                <div id="architecture-diagram"></div>
            </div>
            <div class="grid md:grid-cols-3 gap-4 mt-6">
                <div class="bg-purple-50 p-4 rounded-lg">
                    <h4 class="font-bold text-purple-800 mb-2">Subject 主体</h4>
                    <p class="text-sm text-gray-700">与系统交互的用户或第三方服务，所有 Subject 实例都绑定到 SecurityManager。</p>
                </div>
                <div class="bg-blue-50 p-4 rounded-lg">
                    <h4 class="font-bold text-blue-800 mb-2">SecurityManager 安全管理器</h4>
                    <p class="text-sm text-gray-700">Shiro 架构的心脏，协调内部各安全组件，管理内部组件实例。</p>
                </div>
                <div class="bg-green-50 p-4 rounded-lg">
                    <h4 class="font-bold text-green-800 mb-2">Realms 域</h4>
                    <p class="text-sm text-gray-700">特定安全的 DAO，用于进行身份验证和授权，获取安全相关数据。</p>
                </div>
            </div>
        </div>
        
        <!-- Quick Start Guide -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">快速开始</h2>
            
            <div class="mb-6">
                <h3 class="text-xl font-semibold mb-3">1. 配置文件 (shiro.ini)</h3>
                <pre class="code-block p-4 text-sm"><code>[users]
# 配置规则：用户名=密码,角色名称1，角色名称2
admin = admin,system
qf = 123,qfAdmin

[roles]
# 配置规则：角色名称=权限(多个权限用,号隔开),*代表所有权限
system = *
qfAdmin = user:*</code></pre>
            </div>
            
            <div class="mb-6">
                <h3 class="text-xl font-semibold mb-3">2. 基本使用示例</h3>
                <pre class="code-block p-4 text-sm"><code>// 获取 SecurityManager 工厂
Factory&lt;SecurityManager&gt; factory = new IniSecurityManagerFactory("classpath:shiro.ini");

// 得到 SecurityManager 实例
SecurityManager securityManager = factory.getInstance();

// 绑定给 SecurityUtils
SecurityUtils.setSecurityManager(securityManager);

// 获取当前的 subject
Subject currentUser = SecurityUtils.getSubject();

// 登录操作
UsernamePasswordToken token = new UsernamePasswordToken("admin", "admin");
try {
    currentUser.login(token);
    log.info("登录成功！");
} catch (AuthenticationException ae) {
    log.error("登录失败：" + ae.getMessage());
}</code></pre>
            </div>
        </div>
        
        <!-- Permission System -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">权限系统详解</h2>
            
            <div class="grid md:grid-cols-2 gap-6 mb-6">
                <div>
                    <h3 class="text-xl font-semibold mb-3">编程式授权</h3>
                    <pre class="code-block p-4 text-sm"><code>Subject subject = SecurityUtils.getSubject();
if(subject.hasRole("admin")) {
    // 有权限
} else {
    // 无权限
}</code></pre>
                </div>
                
                <div>
                    <h3 class="text-xl font-semibold mb-3">注解式授权</h3>
                    <pre class="code-block p-4 text-sm"><code>@RequiresRoles("admin")
public void adminMethod() {
    // 需要 admin 角色才能访问
}

@RequiresPermissions("user:update")
public void updateUser() {
    // 需要 user:update 权限
}</code></pre>
                </div>
            </div>
            
            <div class="bg-yellow-50 border-l-4 border-yellow-500 p-4 rounded">
                <p class="text-yellow-800">
                    <i class="fas fa-info-circle mr-2"></i>
                    <strong>权限规则：</strong>资源标识符:操作，如 user:create、user:update、user:delete、user:* 等
                </p>
            </div>
        </div>
        
        <!-- Advanced Features -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">高级特性</h2>
            
            <div class="space-y-6">
                <div class="border-l-4 border-purple-500 pl-6">
                    <h3 class="text-xl font-semibold mb-2">
                        <i class="fas fa-key mr-2 text-purple-500"></i>密码加密
                    </h3>
                    <p class="text-gray-700 mb-3">使用 MD5、SHA 等算法对密码进行加密存储，支持加盐和多次迭代。</p>
                    <pre class="code-block p-3 text-sm"><code>String algorithmName = "MD5";
Object source = "admin";
Object salt = ByteSource.Util.bytes("admin");
int hashIterations = 1024;
SimpleHash simpleHash = new SimpleHash(algorithmName, source, salt, hashIterations);</code></pre>
                </div>
                
                <div class="border-l-4 border-blue-500 pl-6">
                    <h3 class="text-xl font-semibold mb-2">
                        <i class="fas fa-memory mr-2 text-blue-500"></i>缓存管理
                    </h3>
                    <p class="text-gray-700 mb-3">支持 EhCache 等缓存框架，提高认证和授权的性能。</p>
                </div>
                
                <div class="border-l-4 border-green-500 pl-6">
                